<?php
class userMod extends commonMod {
	public function __construct() {
		parent::__construct ();
	}
	public function login() {
		if (empty ( $_SESSION ['uuser'] )) {
			$username=$_POST['user'];
			$password= $_POST['pass'];
			$user_info=$this->model->table ( 'uuser' )->where ( " email = '".$username."'"  )->find ();
			if ($password==$user_info['password']) {
				array_splice($user_info,6);
				$_SESSION['uuser'] = $user_info;
				$this->alert("登录成功", __INDEX__);
			}
			else{
				$this->alert("密码或用户名错误",__INDEX__);
			}
		} 
		else {
			$this->alert("您已登陆",__INDEX__);
		}
	}

	public function reg() {
		$this->display("register.html");
	}

	public function email_exist()
	{
		$isnull=$this->model->table('uuser')->where("email='".$_GET['email']."'")->select();
		if(!empty($isnull)){
			echo "1";
			return;
		}
		else{
			echo "2";
			return;
			 }
	}
	public function reg_save() {
			$data['nickname'] = $_POST['nickname'];
			$data['email'] = $_POST['emailuser'];
			$data['password'] = $_POST['pass'];
			$data['insert_time'] = time();
			$this->model->table('uuser')->data($data)->insert();
			$this->alert("注册成功", __INDEX__);


	}
	public function logout() {
		session_destroy();
		$this->redirect("/100v");
	}

	public function edit_save()
	{
		/*dump($_POST);*/
		if ($_POST['type']="birthday") {
			$_POST['birthday']=strtotime($_POST['birthday']);
		}
		$status = $this->model->table('uuser')->data($_POST)->where("uid=" . $_SESSION['uuser']['uid'])->update();
		if ($status!= false) {
			$user_info=$this->model->table ( 'uuser' )->where ( "uid=" . $_SESSION['uuser']['uid']  )->find ();
			array_splice($user_info,6);
			$_SESSION['uuser'] = $user_info;
			echo '1';
			return;
		} else {
			echo '2';
			return;
		}
	}
}
?>